package com.ruoyi.shanghuliebiao2.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.shanghuliebiao2.domain.CheDrawalStatement;
import com.ruoyi.shanghuliebiao2.service.ICheDrawalStatementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.shanghuliebiao2.domain.CheDrawal;
import com.ruoyi.shanghuliebiao2.service.ICheDrawalService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家提现记录Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/drawal")
public class CheDrawalController extends BaseController
{
    @Autowired
    private ICheDrawalService cheDrawalService;


    @Autowired
    private ICheDrawalStatementService idrawalStatementService;

    /**
     * 查询商家提现记录列表
     */
    @RequiresPermissions("shanghuliebiao2:drawal:list")
    @GetMapping("/list")
    public TableDataInfo list(CheDrawal cheDrawal)
    {
        startPage();
        List<CheDrawal> list = cheDrawalService.selectCheDrawalList(cheDrawal);
        return getDataTable(list);
    }

    /**
     * 导出商家提现记录列表
     */
    @RequiresPermissions("shanghuliebiao2:drawal:export")
    @Log(title = "商家提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheDrawal cheDrawal)
    {
        List<CheDrawal> list = cheDrawalService.selectCheDrawalList(cheDrawal);
        ExcelUtil<CheDrawal> util = new ExcelUtil<CheDrawal>(CheDrawal.class);
        util.exportExcel(response, list, "商家提现记录数据");
    }

    /**
     * 获取商家提现记录详细信息
     */
    @RequiresPermissions("shanghuliebiao2:drawal:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheDrawalService.selectCheDrawalById(id));
    }

    /**
     * 新增商家提现记录
     */
    @RequiresPermissions("shanghuliebiao2:drawal:add")
    @Log(title = "商家提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheDrawal cheDrawal) {
         String card = cheDrawal.getCard();
        cheDrawalService.insertCheDrawal(cheDrawal);
        CheDrawal cheDrawal1 = new CheDrawal();
        cheDrawal1.setCard(card);
         List<CheDrawal> cheDrawals = cheDrawalService.selectCheDrawalList(cheDrawal1);
         for (CheDrawal cheDrawal2 : cheDrawals){
              Long id = cheDrawal2.getId();
             CheDrawalStatement idrawalStatement=new CheDrawalStatement();
             idrawalStatement.setDrawalId(id);
             idrawalStatement.setStatementId(1l);
              idrawalStatementService.insertCheDrawalStatement(idrawalStatement);
         }


        return null;
    }

    /**
     * 修改商家提现记录
     */
    @RequiresPermissions("shanghuliebiao2:drawal:edit")
    @Log(title = "商家提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheDrawal cheDrawal)
    {
        return toAjax(cheDrawalService.updateCheDrawal(cheDrawal));
    }

    /**
     * 删除商家提现记录
     */
    @RequiresPermissions("shanghuliebiao2:drawal:remove")
    @Log(title = "商家提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheDrawalService.deleteCheDrawalByIds(ids));
    }
}
